<?php
include_once("../include/init.php");
$id = $_GET['id'];
$sql = "select * from tk_product where pid =$id";

$res = mysql_query($sql);
$info = [];
if(mysql_num_rows($res)>0){
	while($list = mysql_fetch_assoc($res)){
		$info[] =$list;
	}
}
	foreach($info  as $vo){
		if($id==$vo['pid']){
			$img =$vo['thumb'];
			$price = $vo['price'];
			$sprice = $vo['sprice'];
			$name= $vo['descp'];
			$addr = $vo['addr'];
			$color = $vo['color'];
			$size = $vo['size'];
			$snums =$vo['snums'];
			$pimg = $vo['pimgs'];
		}
	}
			$color2 = explode("-",$color );
			$size2 = explode("-",$size );
			$pimg2 = explode("-",$pimg);
		$sql = "SELECT  user,p_content,p_status,p_time,p_id,pid FROM tk_user u, tk_product p ,tk_pinglun m where p.pid=m.mid and u.uid=m.uid and p.pid = $id";
			$re = mysql_query($sql);
			$comment = [];
		if(mysql_num_rows($res)>0){
			while($list1 = mysql_fetch_assoc($re)){
				$comment[] =$list1;
			}
		}
?>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>商品详情页</title>
	<link rel="stylesheet" href="../public/css/index.css" />
	<link rel="stylesheet" href="../public/css/detail.css"/>
	<style>
#c1{
	width:20px;
	height:20px;
	background:black;
	display:inline-block;
}
#c2{
	width:20px;
	height:20px;
	background:pink;
	display:inline-block ;
}


</style>
</head>
<body>
	<!-- 头部-->
<?php
	include_once("header.php");
?>	

		<!-- 主体-->
		<div class="main">
			<div class="main_nav">
				<ul>
					<li>首页</li>
					<li>平板电脑</li>
					<li>平板电脑</li>
					<li class="last">Apple 苹果</li>

				</ul>
			</div>
			<div class="main_left">
				<img src="<?=$img?>" alt="" id="big" onmouseover="changeImg(this.src)">
				<?php foreach ($pimg2 as $key=>$po){?>
					<img src="../uploads/<?=$po?>" alt="" width="50px" onmouseover="changeImg(this.src)">
				<?php }?>

			</div>
	<script>
		function changeImg(imgSrc){
			var big =document.getElementById('big')
			big.src = imgSrc;
		}

	</script>

			<div class="main_cneter">
				<form action=" addcart.php" method="post">
					<table  cellpadding="0" cellspacing="0" >
						<tr>
							<td colspan="4" class="td_name"><?=$name?></td>
						</tr>
						<tr>
							<td class="td_1">商品价</td>
							<td colspan="3" class="td_2" ><span class="fh">￥</span><?=$price?></td>
						</tr>
						<tr>
							<td class="td_1">优惠</td>
							<td colspan="3" class="td_2"><span class="fh">￥</span><?=$sprice?></td>
						</tr>					
						<tr class="tr_bg">
							<td class="td_1">送到</td>
							<td><select name="" id="" class="select_1">

								<option value="1" selected><?php echo $addr;?></option>
								</select></td>
							<td colspan="2">库存:<?= $snums?></td>
						</tr>
						<tr class="tr_bg">
							<td class="td_1">选择颜色:</td>
							<td>
								<input type="radio" name="color" value="<?=$color2['0'] ?>"/>
								<?php
									if($color2['0']=='black'){
										echo"<div id='c1'></div>";
									}
								?>
							</td>
							<td colspan="2" >
								<input type="radio" name="color" value="<?=$color2['1'] ?>"/>
								<?php
									if($color2['1']=='pink'){
										echo"<div id='c2'></div>";
									}
								?>
							</td>
						</tr>
						<tr class="tr_bg">
							<td class="td_1">选择规格</td>
						<?php foreach($size2 as $key=>$ro){?>
							<td colspan="2"  >							
							<input type="radio" name="size" value="<?=$ro ?>"/>
							<?php 
							if($ro=='64G'){
								echo"64G";
							}elseif($ro=='128G'){
								echo"128G";
							}elseif($ro=='246G'){
								echo"246G";
							}

							?>							
							</td>

						<?php } ?>					

						</tr>
						<tr class="tr_bg">
							<td class="td_1">数量</td>
							<td colspan="3"><button>+</button>
								<input type="text" name="num" value="1" class="num_n">
								<button>-</button>
							</td>						
						</tr>
					<tr>
						<td colspan="4" class="btn_td">	
						<input type="hidden" name="pid" value="<?=$vo['pid']?>">
						<input type="hidden" name="pname" value="<?=$vo['pname']?>">
					 <input type="submit" name="sub"value="加入购物车" class="btn">
					 <button class="btn">立即购买</button>
					 	</td>
					 </tr>						
					</table>
				</form>
			</div>
			<div class="clearfix"></div>			
				<div class="box">
			      <p id="title">
			        <span class="select">商品评价</span>
			        <span>商品介绍</span>
			      </p>
			      <ul id="content">
			        <li class="show">
			        	<table  cellspacing="0"cellpadding="0" class="pj">
								<th>用户名</th>
								<th>评价</th>
								<th>评价内容</th>
								<th>发布时间</th>					
								<?php foreach($comment as $vo){ ?>
									<tr >
										<td><?=$vo['user']?></td>
										<td>
											<?php
											if($vo['p_status']==1){
												echo"满意";
											}elseif($vo['p_status']==2){
												echo"一般";
											}elseif($vo['p_status']==0){
												echo"不满意";
											}
											?>
										</td>
										<td><?=$vo['p_content']?></td>
										<td><?=date("Y-m-d H:i:s",$vo['p_time'])?></td>
								</tr>
								<?php } ;?>
							</table>
			        </li>
			        <li>
			          <?=$name?>
			        </li>
			      </ul>
			    </div>					
			</div>

		<div class="clearfix"></div>
			<!-- 页脚-->
			<?php
             include_once("footer.php");
             ?>
	
</body>
</html>
    <script>
      var title=document.getElementById('title');
      var content=document.getElementById('content');
      var spans=title.getElementsByTagName('span');
      var lis=content.getElementsByTagName('li');
      for (var i = 0; i < spans.length; i++) {
        spans[i].index=i;
          spans[i].onclick=function(){
            for (var j = 0; j < spans.length; j++) {
              spans[j].className='';
              lis[j].className='';
            }
              this.className='select';
              lis[this.index].className='show';
          }
      }
    </script>	